﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
using WeifenLuo.WinFormsUI.Docking;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace BYManageInfoSystem
{
    //http://www.pdfescape.com
    public partial class Frm_TiDanMng : DockContent
    {
        protected string m_strTidanTempletFilePath = @"\TidanTemplate";
        private string m_strFolder = "d:/DGTidan/";
        private DGBY.BLL.FactoryGoodsCHN2ENGTab m_bllFactoryGoodsCHN2ENGTab = new DGBY.BLL.FactoryGoodsCHN2ENGTab();
        private DGBY.BLL.TiDanShipperTab m_bllTiDanShipperTab = new DGBY.BLL.TiDanShipperTab();
        private DGBY.BLL.TiDanTempleteTab m_bllTiDanTempleteTab = new DGBY.BLL.TiDanTempleteTab();
        private DGBY.BLL.BGHarborTab m_bllBGHarborTab = new DGBY.BLL.BGHarborTab();
        private DGBY.BLL.ZYHarborTab m_bllZYHarborTab = new DGBY.BLL.ZYHarborTab();
        private DGBY.BLL.PaidanRegisterTab m_bllPaidanRegisterTab = new DGBY.BLL.PaidanRegisterTab();
        private DGBY.BLL.TiDanTab m_bllTiDanTab = new DGBY.BLL.TiDanTab();
        private DGBY.BLL.TiDanDetailTab m_bllTiDanDetailTab = new DGBY.BLL.TiDanDetailTab();
        private DGBY.BLL.MDCountryTab m_bllMDCountryTab = new DGBY.BLL.MDCountryTab();
        private DGBY.BLL.TiDanConsigneeTab m_bllTiDanConsigneeTab = new DGBY.BLL.TiDanConsigneeTab();
        private DGBY.BLL.TiDanMDCountryPortTab m_bllTiDanMDCountryPortTab = new DGBY.BLL.TiDanMDCountryPortTab();
        private DGBY.BLL.TiDanDeliveryAgentTab m_bllTiDanDeliveryAgentTab = new DGBY.BLL.TiDanDeliveryAgentTab();
        private DGBY.BLL.DG_BackRecoveryMaterialResgistTab m_bllBackRecoveryMaterialResgistTab = new DGBY.BLL.DG_BackRecoveryMaterialResgistTab();
        private int m_nSelectTiDanTabID = 0;
        private Dictionary<int, string> m_Num2Eng = new Dictionary<int, string>();
        private Dictionary<string, int> m_GuiXing2CBM = new Dictionary<string, int>();
        private Dictionary<string, int> m_GuiXing2Weight = new Dictionary<string, int>();
        private Dictionary<int, string> m_Month2Eng = new Dictionary<int, string>();
        public Frm_TiDanMng()
        {
            InitializeComponent();
            m_Num2Eng.Add(1, "ONE");
            m_Num2Eng.Add(2, "TWO");
            m_Num2Eng.Add(3, "THREE");
            m_Num2Eng.Add(4, "FOUR");
            m_Num2Eng.Add(5, "FIVE");
            m_Num2Eng.Add(6, "SIX");
            m_Num2Eng.Add(7, "SEVEN");
            m_Num2Eng.Add(8, "EIGHT");
            m_Num2Eng.Add(9, "NINE");
            m_Num2Eng.Add(10, "TEN");

            m_GuiXing2CBM.Add("20GP", 25);
            m_GuiXing2CBM.Add("40HQ", 65);
            m_GuiXing2CBM.Add("40GP", 57);
            m_GuiXing2CBM.Add("45HQ", 70);
            m_GuiXing2CBM.Add("吨车", 10);

            m_GuiXing2Weight.Add("20GP", 2500);
            m_GuiXing2Weight.Add("40HQ", 3800);
            m_GuiXing2Weight.Add("40GP", 3400);
            m_GuiXing2Weight.Add("45HQ", 4500);

            m_Month2Eng.Add(1, "Jan");
            m_Month2Eng.Add(2, "Feb");
            m_Month2Eng.Add(3, "Mar");
            m_Month2Eng.Add(4, "Apr");
            m_Month2Eng.Add(5, "May");
            m_Month2Eng.Add(6, "Jun");
            m_Month2Eng.Add(7, "Jul");
            m_Month2Eng.Add(8, "Aug");
            m_Month2Eng.Add(9, "Sep");
            m_Month2Eng.Add(10, "Oct");
            m_Month2Eng.Add(11, "Nov");
            m_Month2Eng.Add(12, "Dec");
        }
        private void InitCombox()
        {
            DataSet ds = m_bllPaidanRegisterTab.GetNameAndIDAll("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxContractNo.DataSource = ds.Tables[0];
                this.comboBoxContractNo.ValueMember = "PaidanRegisterTabID";
                this.comboBoxContractNo.DisplayMember = "合同编号";
                this.comboBoxContractNo.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxContractNo.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxContractNo.SelectedIndex = 0;
            }
            ds = m_bllMDCountryTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxTargetCountry.DataSource = ds.Tables[0];
                this.comboBoxTargetCountry.DisplayMember = "国家名称";
                this.comboBoxTargetCountry.ValueMember = "MDCountryTabID";
                this.comboBoxTargetCountry.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxTargetCountry.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxTargetCountry.SelectedIndex = 0;
            }
            ds = m_bllZYHarborTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxPort.DataSource = ds.Tables[0];
                this.comboBoxPort.DisplayMember = "装运港名称";
                this.comboBoxPort.ValueMember = "ZYHarborTabID";
                this.comboBoxPort.SelectedIndex = 0;
            }
            ds = m_bllBGHarborTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxBGPort.DataSource = ds.Tables[0];
                this.comboBoxBGPort.DisplayMember = "报关港";
                this.comboBoxBGPort.ValueMember = "BGHarborTabID";
                this.comboBoxBGPort.SelectedIndex = 0;
            }
            ds = m_bllTiDanTempleteTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxTiDanTemplete.DataSource = ds.Tables[0];
                this.comboBoxTiDanTemplete.DisplayMember = "提单模板名称";
                this.comboBoxTiDanTemplete.ValueMember = "TiDanTempleteTabID";
                this.comboBoxTiDanTemplete.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxTiDanTemplete.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxTiDanTemplete.SelectedIndex = 0;
            }
            //ds = m_bllTiDanShipperTab.GetList("");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    this.comboBoxShipper.DataSource = ds.Tables[0];
            //    this.comboBoxShipper.DisplayMember = "Shipper内容";
            //    this.comboBoxShipper.ValueMember = "TiDanShipperTabID";
            //    this.comboBoxShipper.AutoCompleteSource = AutoCompleteSource.ListItems;
            //    this.comboBoxShipper.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            //    this.comboBoxShipper.SelectedIndex = 0;
            //}
            ds = m_bllFactoryGoodsCHN2ENGTab.GetList("");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                this.comboBoxGoodsEng.DataSource = ds.Tables[0];
                this.comboBoxGoodsEng.DisplayMember = "货品种类英文";
                this.comboBoxGoodsEng.ValueMember = "FactoryGoodsCHN2ENGTabID";
                this.comboBoxGoodsEng.AutoCompleteSource = AutoCompleteSource.ListItems;
                this.comboBoxGoodsEng.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
                this.comboBoxGoodsEng.SelectedIndex = 0;
            }
            //ds = m_bllTiDanDeliveryAgentTab.GetList("");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    this.comboBoxDeliveryAgentTab.DataSource = ds.Tables[0];
            //    this.comboBoxDeliveryAgentTab.DisplayMember = "DeliveryAgent";
            //    this.comboBoxDeliveryAgentTab.ValueMember = "TiDanDeliveryAgentTabID";
            //    this.comboBoxDeliveryAgentTab.AutoCompleteSource = AutoCompleteSource.ListItems;
            //    this.comboBoxDeliveryAgentTab.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            //    this.comboBoxDeliveryAgentTab.SelectedIndex = 0;
            //}
            //ds = m_bllTiDanConsigneeTab.GetList("");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    this.comboBoxConsignee.DataSource = ds.Tables[0];
            //    this.comboBoxConsignee.DisplayMember = "Consignee";
            //    this.comboBoxConsignee.ValueMember = "TiDanConsigneeTabID";
            //    this.comboBoxConsignee.AutoCompleteSource = AutoCompleteSource.ListItems;
            //    this.comboBoxConsignee.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            //    this.comboBoxConsignee.SelectedIndex = 0;
            //}
            //ds = m_bllTiDanMDCountryPortTab.GetList("");
            //if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            //{
            //    this.comboBoxTiDanMDCountryPort.DataSource = ds.Tables[0];
            //    this.comboBoxTiDanMDCountryPort.DisplayMember = "港口";
            //    this.comboBoxTiDanMDCountryPort.ValueMember = "TiDanMDCountryPortTabID";
            //    this.comboBoxTiDanMDCountryPort.AutoCompleteSource = AutoCompleteSource.ListItems;
            //    this.comboBoxTiDanMDCountryPort.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            //    this.comboBoxTiDanMDCountryPort.SelectedIndex = 0;
            //}
        }
        private void Frm_TiDanMng_Load(object sender, EventArgs e)
        {
            InitCombox();
        }
        	
   

        private void comboBoxContractNo_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string strContractNo = this.comboBoxContractNo.SelectedValue.ToString();
                int nID = Convert.ToInt32(strContractNo, 10);
                DataSet dsShipper = m_bllTiDanShipperTab.GetAllList();
                DataSet ds = m_bllPaidanRegisterTab.GetTidanInfo("PaidanRegisterTab.PaidanRegisterTabID = '" + nID + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {

                    //int nTiDanConsigneeTabid = ds.Tables[0].Rows[0]["TiDanConsigneeTabid"].ToString() != "" ? (int)ds.Tables[0].Rows[0]["TiDanConsigneeTabid"] : 0;
                    //int nTiDanMDCountryPortTabid = ds.Tables[0].Rows[0]["TiDanMDCountryPortTabid"].ToString() != "" ? (int)ds.Tables[0].Rows[0]["TiDanMDCountryPortTabid"] : 0;
                    //int nTiDanDeliveryAgentTabid = ds.Tables[0].Rows[0]["TiDanDeliveryAgentTabid"].ToString() != "" ? (int)ds.Tables[0].Rows[0]["TiDanDeliveryAgentTabid"] : 0;
                    //this.comboBoxConsignee.SelectedValue = nTiDanConsigneeTabid;
                    //this.comboBoxTiDanMDCountryPort.SelectedValue = nTiDanMDCountryPortTabid;
                    //this.comboBoxDeliveryAgentTab.SelectedValue = nTiDanDeliveryAgentTabid;
                    int nFactoryGoodsCHN2ENGTabID = ds.Tables[0].Rows[0]["FactoryGoodsCHN2ENGTabID"].ToString() != "" ? (int)ds.Tables[0].Rows[0]["FactoryGoodsCHN2ENGTabID"] : 0; 
                    int nMDCountryTabID = (int)ds.Tables[0].Rows[0]["MDCountryTabID"];
                    int nZYHarborTabID = (int)ds.Tables[0].Rows[0]["ZYHarborTabID"];
                    int nBGHarborTabID = (int)ds.Tables[0].Rows[0]["BGHarborTabID"];
                    this.comboBoxGoodsEng.SelectedValue = nFactoryGoodsCHN2ENGTabID;
                    this.comboBoxTargetCountry.SelectedValue = nMDCountryTabID;
                    this.comboBoxPort.SelectedValue = nZYHarborTabID;
                    this.comboBoxBGPort.SelectedValue = nBGHarborTabID;
                    
                    this.textBoxFacName.Text = ds.Tables[0].Rows[0]["工厂简称"].ToString();
                    this.textBoxGoodsName.Text = ds.Tables[0].Rows[0]["货品种类"].ToString();
                    this.textBoxShipNameHangCi.Text = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    DateTime dt = (DateTime)ds.Tables[0].Rows[0]["签订日期"];
                    this.dateTimePickerMakeProtocolDate.Value = dt.Date.AddDays(5);
                    this.richTextBoxShipper.Text = dsShipper.Tables[0].Rows[0]["Shipper内容"].ToString();
                }


            }
            catch { }
        }

        private void buttonProduce_Click(object sender, EventArgs e)
        {
            try
            {
                string strContractNo = this.comboBoxContractNo.SelectedValue.ToString();
                int nID = Convert.ToInt32(strContractNo, 10);
                DataSet ds = m_bllTiDanTab.GetList("PaidanRegisterTabID = '" + nID + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    MessageBox.Show("该合同号的提单已经存在,请不要重复生成！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                else
                {
                    DGBY.Model.TiDanTab modelTiDanTab = new DGBY.Model.TiDanTab();
                    modelTiDanTab.PaidanRegisterTabID = nID;
                    modelTiDanTab.TiDanTempleteTabID = Convert.ToInt32(this.comboBoxTiDanTemplete.SelectedValue.ToString(), 10);
                    modelTiDanTab.TiDanShipperTabID = 0;
                    modelTiDanTab.TiDanConsigneeTabID = 0;
                    modelTiDanTab.TiDanMDCountryPortTabID = 0;
                    modelTiDanTab.TiDanDeliveryAgentTabID = 0;
                    modelTiDanTab.TiDanShipper = this.richTextBoxShipper.Text;
                    modelTiDanTab.TiDanConsignee = this.richTextBoxConsignee.Text;
                    modelTiDanTab.TiDanDeliveryAgent = this.richTextBoxDeliveryAgent.Text;
                    modelTiDanTab.TiDanMDCountryPort = this.richTextBoxMDPort.Text;
                    //modelTiDanTab.TiDanShipperTabID = Convert.ToInt32(this.comboBoxShipper.SelectedValue.ToString(), 10);
                    //modelTiDanTab.TiDanConsigneeTabID = this.comboBoxConsignee.SelectedValue == null ? 1 : Convert.ToInt32(this.comboBoxConsignee.SelectedValue.ToString(), 10);
                    //modelTiDanTab.TiDanMDCountryPortTabID = this.comboBoxTiDanMDCountryPort.SelectedValue == null ? 1 : Convert.ToInt32(this.comboBoxTiDanMDCountryPort.SelectedValue.ToString(), 10);
                    //modelTiDanTab.TiDanDeliveryAgentTabID = this.comboBoxDeliveryAgentTab.SelectedValue == null ? 1 : Convert.ToInt32(this.comboBoxDeliveryAgentTab.SelectedValue.ToString(), 10);
                    modelTiDanTab.FactoryGoodsCHN2ENGTabID = this.comboBoxGoodsEng.SelectedValue == null ? 1 : Convert.ToInt32(this.comboBoxGoodsEng.SelectedValue.ToString(), 10);
                    modelTiDanTab.MDCountryTabID = Convert.ToInt32(this.comboBoxTargetCountry.SelectedValue.ToString(), 10);
                    modelTiDanTab.BGHarborTabID = Convert.ToInt32(this.comboBoxBGPort.SelectedValue.ToString(), 10);
                    modelTiDanTab.ZYHarborTabID = Convert.ToInt32(this.comboBoxPort.SelectedValue.ToString(), 10);
                    modelTiDanTab.NotifyPart = this.textBoxNotifyPart.Text;
                    modelTiDanTab.ShipNameHangCi = this.textBoxShipNameHangCi.Text;
                    modelTiDanTab.ShipDate = this.dateTimePickerMakeProtocolDate.Value.Date;
                    modelTiDanTab.ReservField1 = "";
                    modelTiDanTab.ReservField2 = "";
                    modelTiDanTab.ReservID1 = 0;
                    modelTiDanTab.ReservID1 = 0;
                    modelTiDanTab.TidanProduceDate = System.DateTime.Now.Date;
                    modelTiDanTab.UserPasswordTabID = Frm_Main.m_nLoginUserId;
                    m_bllTiDanTab.Add(modelTiDanTab);
                    ds = m_bllTiDanTab.GetList("PaidanRegisterTabID = '" + nID + "'");
                    int nTiDanTabID = (int)ds.Tables[0].Rows[0]["TiDanTabID"];
                    ds = m_bllPaidanRegisterTab.GetTidanDetailInfo("PaidanRegisterTab.PaidanRegisterTabID = '" + nID + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            DGBY.Model.TiDanDetailTab modelTiDanDetailTab = new DGBY.Model.TiDanDetailTab();
                            modelTiDanDetailTab.TiDanTabID = nTiDanTabID;
                            modelTiDanDetailTab.MaoZhong = (int)((Decimal)ds.Tables[0].Rows[i]["总毛重"]);
                            modelTiDanDetailTab.PieceNum = (int)ds.Tables[0].Rows[i]["总件数"];
                            modelTiDanDetailTab.GuiXingTabID = (int)ds.Tables[0].Rows[i]["GuiXingTabID"];
                            modelTiDanDetailTab.DingCangNo = ds.Tables[0].Rows[i]["DingCangNo"].ToString();
                            modelTiDanDetailTab.GuiNo = ds.Tables[0].Rows[i]["GuiNo"].ToString();
                            modelTiDanDetailTab.FengTiaoNo = ds.Tables[0].Rows[i]["FengTiao"].ToString();
                            modelTiDanDetailTab.ReservField1 = "";
                            modelTiDanDetailTab.ReservField2 = "";
                            modelTiDanDetailTab.ReservID1 = 0;
                            modelTiDanDetailTab.ReservID2 = 0;

                            int nResult = m_bllTiDanDetailTab.Add(modelTiDanDetailTab);
                            if (nResult != 1)
                            {
                                /************************************************************/
                                //增加提单成功后 更新综合登记表提单记录
                                m_bllTiDanDetailTab.UpdateTDbyPaidanRegisterTabID(nID);
                                /************************************************************/                      
                            }
                        }
                    }

                    /************************************************************/
                    //更新备案资料回收登记表
                    DGBY.Model.DG_BackRecoveryMaterialResgistTab oldModelBackRecoveryMaterialTab = m_bllBackRecoveryMaterialResgistTab.GetModelByPaidanRegisterTabID(modelTiDanTab.PaidanRegisterTabID);
                    if (null == oldModelBackRecoveryMaterialTab)
                        return;

                    if (oldModelBackRecoveryMaterialTab.td != 2)
                    {
                        oldModelBackRecoveryMaterialTab.td = 3;
                        m_bllBackRecoveryMaterialResgistTab.Update(oldModelBackRecoveryMaterialTab);
                    }
                    /************************************************************/

                    Frm_Main.Log2DB(this.Text, "生成提单", this.comboBoxContractNo.Text + "(" + nTiDanTabID.ToString() + ")");

                    ShowAllRecord("TiDanTab.TiDanTabid = '" + nTiDanTabID.ToString() + "'");
                    MessageBox.Show("生成提单成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    
                }

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
        private void ShowAllRecord(string strWhere)
        {
            DataSet ds = m_bllTiDanTab.GetAllRecord(strWhere);

            ultraGrid1.DataSource = null;
            ultraGrid2.DataSource = null;
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ultraGrid1.DataSource = ds.Tables[0];
                ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            }
        }

        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            ShowAllRecord("");
        }

        private void buttonMod_Click(object sender, EventArgs e)
        {
            try
            {
               
         
                DGBY.Model.TiDanTab modelTiDanTab = m_bllTiDanTab.GetModel(m_nSelectTiDanTabID);
                if (modelTiDanTab != null)
                {
                    
                    modelTiDanTab.TiDanTempleteTabID = Convert.ToInt32(this.comboBoxTiDanTemplete.SelectedValue.ToString(), 10);
                    modelTiDanTab.TiDanShipperTabID = 0;
                    modelTiDanTab.TiDanConsigneeTabID = 0;
                    modelTiDanTab.TiDanMDCountryPortTabID = 0;
                    modelTiDanTab.TiDanDeliveryAgentTabID = 0;
                    modelTiDanTab.TiDanShipper = this.richTextBoxShipper.Text;
                    modelTiDanTab.TiDanConsignee = this.richTextBoxConsignee.Text;
                    modelTiDanTab.TiDanDeliveryAgent = this.richTextBoxDeliveryAgent.Text;
                    modelTiDanTab.TiDanMDCountryPort = this.richTextBoxMDPort.Text;
                    //modelTiDanTab.TiDanShipperTabID = Convert.ToInt32(this.comboBoxShipper.SelectedValue.ToString(), 10);
                    //modelTiDanTab.TiDanConsigneeTabID = this.comboBoxConsignee.SelectedValue == null ? 1 : Convert.ToInt32(this.comboBoxConsignee.SelectedValue.ToString(), 10);
                    //modelTiDanTab.TiDanMDCountryPortTabID = this.comboBoxTiDanMDCountryPort.SelectedValue == null ? 1 : Convert.ToInt32(this.comboBoxTiDanMDCountryPort.SelectedValue.ToString(), 10);
                    //modelTiDanTab.TiDanDeliveryAgentTabID = this.comboBoxDeliveryAgentTab.SelectedValue == null ? 1 : Convert.ToInt32(this.comboBoxDeliveryAgentTab.SelectedValue.ToString(), 10);
                    modelTiDanTab.FactoryGoodsCHN2ENGTabID = this.comboBoxGoodsEng.SelectedValue == null ? 1 : Convert.ToInt32(this.comboBoxGoodsEng.SelectedValue.ToString(), 10);
                    modelTiDanTab.MDCountryTabID = Convert.ToInt32(this.comboBoxTargetCountry.SelectedValue.ToString(), 10);
                    modelTiDanTab.BGHarborTabID = Convert.ToInt32(this.comboBoxBGPort.SelectedValue.ToString(), 10);
                    modelTiDanTab.ZYHarborTabID = Convert.ToInt32(this.comboBoxPort.SelectedValue.ToString(), 10);
                    modelTiDanTab.NotifyPart = this.textBoxNotifyPart.Text;
                    modelTiDanTab.ShipNameHangCi = this.textBoxShipNameHangCi.Text;
                    modelTiDanTab.ShipDate = this.dateTimePickerMakeProtocolDate.Value.Date;
                    modelTiDanTab.ReservField1 = "";
                    modelTiDanTab.ReservField2 = "";
                    modelTiDanTab.ReservID1 = 0;
                    modelTiDanTab.ReservID1 = 0;
                    m_bllTiDanTab.Update(modelTiDanTab);

                    Frm_Main.Log2DB(this.Text, "修改", this.comboBoxContractNo.Text + "(" + modelTiDanTab.TiDanTempleteTabID.ToString() + ")");

                    ShowAllRecord("PaidanRegisterTab.ContractCode = '" + this.comboBoxContractNo.Text + "'");
                    MessageBox.Show("修改提单成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

          

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void buttonDel_Click(object sender, EventArgs e)
        {
            try
            {


                DGBY.Model.TiDanTab modelTiDanTab = m_bllTiDanTab.GetModel(m_nSelectTiDanTabID);
                if (modelTiDanTab != null)
                {

                    if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        m_bllTiDanDetailTab.DeleteByTiDanID(m_nSelectTiDanTabID);
                        m_bllTiDanTab.Delete(m_nSelectTiDanTabID);

                        Frm_Main.Log2DB(this.Text, "删除", this.comboBoxContractNo.Text + "(" + modelTiDanTab.TiDanTempleteTabID.ToString() + ")");


                        m_bllTiDanDetailTab.UpdateTDbyPaidanRegisterTabIDToZero(modelTiDanTab.PaidanRegisterTabID);
                        /************************************************************/
                        //更新备案资料回收登记表
                        DGBY.Model.DG_BackRecoveryMaterialResgistTab oldModelBackRecoveryMaterialTab = m_bllBackRecoveryMaterialResgistTab.GetModelByPaidanRegisterTabID(modelTiDanTab.PaidanRegisterTabID);
                        if (null == oldModelBackRecoveryMaterialTab)
                            return;

                        if (oldModelBackRecoveryMaterialTab.td != 2)
                        {
                            oldModelBackRecoveryMaterialTab.td = 4;
                            m_bllBackRecoveryMaterialResgistTab.Update(oldModelBackRecoveryMaterialTab);
                        }
                        /************************************************************/

                        MessageBox.Show("删除提单成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ShowAllRecord("");
                    }
                }
                else
                {

                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;

                }



            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }
        private string SplitGuiXing(string strGuiXing)
        {
            return strGuiXing.Substring(0, 2) + "'" + strGuiXing.Substring(2, 2);
        }
        private string SplitGuiXingEx(string strGuiXing)
        {
            return strGuiXing.Substring(0, 2) + "'";
        }
        #region MAERSK
        private void ProduceMaersk(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DingCangNo2", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPort", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();

                    string[] strArray = strChuanNameHangCi.Split(' ');
                    string strChuanName = "";
                    for (int k = 0; k < strArray.Length - 1; k++)
                        strChuanName += strArray[k];
                    string strHangCi = strArray[strArray.Length - 1];
                    coderBlogForm.SetField("ShipName", strChuanName);
                    coderBlogForm.SetField("HangCi", strHangCi);

                    //coderBlogForm.SetField("NumSeq", m_Num2Eng[ds2.Tables[0].Rows.Count] + "/" + ds2.Tables[0].Rows.Count);
                    coderBlogForm.SetField("BoxNum", ds2.Tables[0].Rows.Count + " container(s)");
                    coderBlogForm.SetField("ShipDate", ((DateTime)ds.Tables[0].Rows[0]["ShipDate"]).ToShortDateString());
                    coderBlogForm.SetField("BGPort", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("ZYPort", ds.Tables[0].Rows[0]["装运港"].ToString());
                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;

                        Random rd = new Random();
                        int a = rd.Next(-20000, 20000);
                        Decimal f = (Decimal)(a * 0.0001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;
                       
                        strFinal += strGuiNo + " " + strFengTiaoNo + " " + strGuiXingName.Substring(0, 2)
                            + " " + "DRY" + strGuiXingTypeName + " " + nPieceNum + " carton " + nMaoZhong
                            + ".000 KGS " + dCBM + " CBM" + "\n";
                    }
                  
                    coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".000 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal + " CBM");
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("Summary", ds2.Tables[0].Rows.Count + " container said to contain " + nTotalPieceNum + " carton");
                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
          
        }
        #endregion
        #region SAFMARINE
        private void ProduceSafmarine(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DingCangNo2", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPort", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();

                    string[] strArray = strChuanNameHangCi.Split(' ');
                    string strChuanName = "";
                    for (int k = 0; k < strArray.Length - 1; k++)
                        strChuanName += strArray[k];
                    string strHangCi = strArray[strArray.Length - 1];
                    coderBlogForm.SetField("ShipName", strChuanName);
                    coderBlogForm.SetField("HangCi", strHangCi);

                    //coderBlogForm.SetField("NumSeq", m_Num2Eng[ds2.Tables[0].Rows.Count] + "/" + ds2.Tables[0].Rows.Count);
                    coderBlogForm.SetField("BoxNum", ds2.Tables[0].Rows.Count + " container(s)");
                    coderBlogForm.SetField("ShipDate", ((DateTime)ds.Tables[0].Rows[0]["ShipDate"]).ToShortDateString());
                    coderBlogForm.SetField("BGPort", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("ZYPort", ds.Tables[0].Rows[0]["装运港"].ToString());
                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;

                        Random rd = new Random();
                        int a = rd.Next(-20000, 20000);
                        Decimal f = (Decimal)(a * 0.0001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strFinal += strGuiNo + " " + strFengTiaoNo + " " + strGuiXingName.Substring(0, 2)
                            + " " + "DRY" + strGuiXingTypeName + " " + nPieceNum + " carton " + nMaoZhong
                            + ".000 KGS " + dCBM + " CBM" + "\n";
                    }

                    coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".000 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal + " CBM");
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("Summary", ds2.Tables[0].Rows.Count + " container said to contain " + nTotalPieceNum + " carton");
                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region CITITRANS
        private void ProduceCititrans(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort", ds.Tables[0].Rows[0]["报关港"].ToString());
                    
                    coderBlogForm.SetField("BoxNum", ds2.Tables[0].Rows.Count + " container(s)");
                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strMonth + "." + strDay + "," + strYear);
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPortShipDate", strZYPort + " " + strMonth + "." + strDay + "," + strYear);
                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-20000, 20000);
                        Decimal f = (Decimal)(a * 0.0001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strFinal += strGuiNo.TrimEnd() + "/" + strFengTiaoNo.TrimEnd() + "/" + SplitGuiXing(strGuiXing) + "/" + nPieceNum + " CTNS/" + nMaoZhong
                            + ".000KGS/" + dCBM + " CBM" + "\n";
                    }

                    coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".000 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal + " CBM");
                    coderBlogForm.SetField("GoodsName", "CHINESE MADE "+ ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("Summary", nTotalPieceNum + " CTNS");
                    coderBlogForm.SetField("GuiCountGuiXing1", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    coderBlogForm.SetField("GuiCountGuiXing2", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    coderBlogForm.SetField("GuiCountGuiXing3", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")");
                  //  coderBlogForm.SetField("GuiCountGuiXing3", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")");
            
                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region INTERGLOBO
        private void ProduceInterglobo(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort1", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());

                    //coderBlogForm.SetField("PieceNum", ds2.Tables[0].Rows.Count + "CTNS");


                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strDay + "-" + strMonth + "-" + strYear);
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPortShipDate", strZYPort + " " + strDay + "-" + strMonth + "-" + strYear);


                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-20000, 20000);
                        Decimal f = (Decimal)(a * 0.0001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strFinal += strGuiNo.TrimEnd() + " / " + strFengTiaoNo.TrimEnd() + "\n";
                    }

                    coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".000 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal + " CBM");
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("Summary", nTotalPieceNum + " CTNS");
                    coderBlogForm.SetField("GuiCountGuiXing1", ds2.Tables[0].Rows.Count + "X" + strGuiXing);
                    //coderBlogForm.SetField("GuiCountGuiXing2", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    coderBlogForm.SetField("GuiCountGuiXing2", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")");
                

                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region PANTAINER
        private void ProducePantainer(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort", ds.Tables[0].Rows[0]["报关港"].ToString());
                 

                    //coderBlogForm.SetField("PieceNum", ds2.Tables[0].Rows.Count + "CTNS");


                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = dtShipDate.Month.ToString();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strDay + "/" + strMonth + "/" + strYear);
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPort", strZYPort);


                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-20000, 20000);
                        Decimal f = (Decimal)(a * 0.0001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;
                        if (i > 2)
                            break;

                        coderBlogForm.SetField("GuiNo" + (i+1).ToString(), "CONT-NO " + strGuiNo);
                        coderBlogForm.SetField("FengTiaoNo" + (i + 1), "SL:" + strFengTiaoNo);
                        coderBlogForm.SetField("V" + (i + 1).ToString(), "V:");
                        coderBlogForm.SetField("CBM" + (i + 1).ToString(), dCBM.ToString());
                        coderBlogForm.SetField("GuiXing" + (i + 1).ToString(), "1 " + strGuiXing);
                        coderBlogForm.SetField("PieceNum" + (i + 1).ToString(), nPieceNum + "CTNS");
                        coderBlogForm.SetField("MaoZhong" + (i + 1).ToString(), nMaoZhong + ".00");
                    }

                    //coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".00 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal + " CBM");
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("PieceNum", "( " + nTotalPieceNum.ToString());
                    coderBlogForm.SetField("BoxNum", ds2.Tables[0].Rows.Count.ToString());
                    coderBlogForm.SetField("BoxNum1", ds2.Tables[0].Rows.Count.ToString());
                    coderBlogForm.SetField("GuiCountGuiXing1", ds2.Tables[0].Rows.Count + "X" + strGuiXing);
                    //coderBlogForm.SetField("GuiCountGuiXing2", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    //coderBlogForm.SetField("GuiCountGuiXing2", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")");


                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region XINLUO
        private void ProduceXinluo(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry3", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort1", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());

                  

                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strMonth + "," + strDay + "," + strYear);
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ShipDate2", strMonth + "," + strDay + "," + strYear + " " + strZYPort);


                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-20000, 20000);
                        Decimal f = (Decimal)(a * 0.0001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strFinal += strGuiNo.TrimEnd() + "/" + strFengTiaoNo.TrimEnd() + "/" + SplitGuiXing(strGuiXing) + "\n";
                    }
                    coderBlogForm.SetField("Summary", "SAY TOTAL " + m_Num2Eng[ds2.Tables[0].Rows.Count] + " CONTAINER(S) (" + ds2.Tables[0].Rows.Count + "X" + strGuiXing + ") ONLY");
                    coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".000 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal + "CBM");
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("PieceNum", nTotalPieceNum.ToString() + "CTNS");
                    coderBlogForm.SetField("GuiCountGuiXing1", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    //coderBlogForm.SetField("GuiCountGuiXing2", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    //coderBlogForm.SetField("GuiCountGuiXing2", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")");


                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region JUST
        private void ProduceJust(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DingCangNo2", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort", ds.Tables[0].Rows[0]["报关港"].ToString());
        



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate", strDay + "-" + strMonth + "-" + strYear.Substring(2,2));
                    //string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    //coderBlogForm.SetField("ShipDate2", strMonth + "," + strDay + "," + strYear + " " + strZYPort);


                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-20000, 20000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strFinal += strGuiNo.TrimEnd() + "/" + strFengTiaoNo.TrimEnd() + "/" + nPieceNum + "CTNS/" + nMaoZhong
                           + ".000 KGS/" + dCBM + "CBM" + "\n";
                    }
                    coderBlogForm.SetField("GuiCountGuiXing1", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + strGuiXing + ")");
                    coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("MaoZhong1", nTotalMaoZhong.ToString() + ".00KGS");
                    coderBlogForm.SetField("MaoZhong2", nTotalMaoZhong.ToString() + ".00KGS");
                    coderBlogForm.SetField("CBM1", dCBMTotal.ToString());
                    coderBlogForm.SetField("CBM2", dCBMTotal.ToString());
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("PieceNum1", nTotalPieceNum.ToString() + "CTNS");
                    coderBlogForm.SetField("PieceNum2", nTotalPieceNum.ToString() + "CTNS");
                    //coderBlogForm.SetField("GuiCountGuiXing1", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    //coderBlogForm.SetField("GuiCountGuiXing2", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    //coderBlogForm.SetField("GuiCountGuiXing2", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")");


                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region SUMMIT
        private void ProduceSummit(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DingCangNo2", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DingCangNo3", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DingCangNo4", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort1", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strDay + "-" + strMonth + "-" + strYear);
                    coderBlogForm.SetField("Month", dtShipDate.Month.ToString().PadLeft(2, '0'));
                    coderBlogForm.SetField("Day", strDay);
                    coderBlogForm.SetField("Year", strYear);

                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";


                    strFinal += String.Format("{0,-20}", "Container") + String.Format("{0,-20}", "Seals")
                              + String.Format("{0,-12}", "Type") + String.Format("{0,-12}", "Weight(KG)")
                              + String.Format("{0,-12}", "Volume(M3)") + String.Format("{0,-12}", "Packages")
                              + String.Format("{0,-12}", "Mode") + "\n";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-20000, 20000);
                        Decimal f = (Decimal)(a * 0.0001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strGuiNo = String.Format("{0,-20}",strGuiNo);
                        strFengTiaoNo = String.Format("{0,-20}", strFengTiaoNo);
                        string strGuiXingSingle = String.Format("{0,-12}", strGuiXing);
                        string strMaoZhong = String.Format("{0,-12}", nMaoZhong.ToString());
                        string strCBM = String.Format("{0,-12}", dCBM.ToString());
                        string strPieceNum = String.Format("{0,-12}", nPieceNum.ToString());
                        string strMode = String.Format("{0,-12}", "CY/CY*");
                        strFinal += strGuiNo.TrimEnd() + "    " + strFengTiaoNo.TrimEnd() + "    " + strGuiXingSingle
                                    + strMaoZhong + strCBM + strPieceNum + strMode + "\n";
                    }
                    coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".00 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal + " M3");
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("PieceNum", nTotalPieceNum.ToString());
                    coderBlogForm.SetField("GuiCount", ds2.Tables[0].Rows.Count.ToString());
                    coderBlogForm.SetField("GuiXing1", "x" + strGuiXing);
                   

                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region IFL
        private void ProduceIfl(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    //coderBlogForm.SetField("DingCangNo2", ds2.Tables[0].Rows[0]["订仓号"].ToString());
    
                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort", ds.Tables[0].Rows[0]["报关港"].ToString());

                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strMonth + "." + strDay + "," + strYear);
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPortShipDate", strZYPort + " " + strMonth + "." + strDay + "," + strYear);

                    
                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXingName = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;

                        Random rd = new Random();
                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strFinal += strGuiNo + "/" + strFengTiaoNo + "/" + SplitGuiXing(strGuiXingName) + "/" + nPieceNum + " CTNS " + "/" + nMaoZhong
                            + ".000 KGS " + "/" + dCBM + " CBM" + "\n";
                    }

                    coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".000 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal + " CBM");
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("GuiCountGuiXing1", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXingName) + ")");
                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region ANL
        private void ProduceAnl(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
           
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort", ds.Tables[0].Rows[0]["报关港"].ToString());
                   



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strDay + "-" + strMonth + "-" + strYear);
                    coderBlogForm.SetField("ShipDate2", strDay + " " + strMonth + " " + strYear);
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPort", strZYPort);
                    coderBlogForm.SetField("ZYPort2", strZYPort);

                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";


                    
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strGuiNo = String.Format("{0,-30}", strGuiNo);
                        
                        string strGuiXingSingle = String.Format("{0,-20}", strGuiXing);
                        string strPieceNum = String.Format("{0,-75}", nPieceNum.ToString() + " CARTONS");
                        string strMaoZhong = String.Format("{0,-20}", nMaoZhong.ToString() + ".000");
                        string strCBM = String.Format("{0,-20}", dCBM.ToString());
                        
                        string strGuiWeight = String.Format("{0,-20}", m_GuiXing2Weight[strGuiXing].ToString());
                        strFinal += strGuiNo + "   1 x " + strGuiXingSingle
                                     + strPieceNum + strMaoZhong + strGuiWeight + strCBM + "\n";

                        strFengTiaoNo = String.Format("{0,-30}", strFengTiaoNo);
                        strFinal += "SEAL " + strFengTiaoNo + "\n";
                    }
                    coderBlogForm.SetField("Summary2", strFinal);

                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong.ToString());
                    coderBlogForm.SetField("CBM", dCBMTotal.ToString());
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("PieceNum", ds2.Tables[0].Rows.Count.ToString());
                    //coderBlogForm.SetField("GuiCount", ds2.Tables[0].Rows.Count.ToString());
                    //coderBlogForm.SetField("GuiXing1", "x" + strGuiXing);


                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region GSL
        private void ProduceGsl(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                   // coderBlogForm.SetField("MDPortMDCountry3", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort", ds.Tables[0].Rows[0]["报关港"].ToString());
                    //coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    //coderBlogForm.SetField("ShipDate1", strMonth + "," + strDay + "," + strYear);
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPortShipDate", strZYPort + "  " + strMonth + "," + strDay + "," + strYear);


                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strFinal += strGuiNo.TrimEnd() + "/" + SplitGuiXing(strGuiXing) + "/" + strFengTiaoNo.TrimEnd()
                            + "/" + nPieceNum.ToString() + " CTNS/" + nMaoZhong.ToString() + ".00 KGS/" + dCBM.ToString() + "CBM/" + "\n";
                    }
                    coderBlogForm.SetField("GuiCountGuiXing2", "SAY " + m_Num2Eng[ds2.Tables[0].Rows.Count] + " (" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")CONTAINER ONLY");
                    coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".00 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal + "CBM");
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("PieceNum", nTotalPieceNum.ToString());
                    coderBlogForm.SetField("GuiCountGuiXing1", "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")CONTAINER S.T.C.");
                    //coderBlogForm.SetField("GuiCountGuiXing2", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    //coderBlogForm.SetField("GuiCountGuiXing2", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")");


                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region SEAMASTER
        private void ProduceSeaMaster(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                
                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort1", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strMonth + "-" + strDay + "-" + strYear);
                    coderBlogForm.SetField("Month", dtShipDate.Month.ToString().PadLeft(2, '0'));
                    coderBlogForm.SetField("Day", strDay);
                    coderBlogForm.SetField("Year", strYear);

                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPort", strZYPort);

                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";


                   
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strGuiNo = String.Format("{0,-30}", strGuiNo);
                        string strGuiXingSingle = String.Format("{0,-20}", SplitGuiXingEx(strGuiXing));
                        strFengTiaoNo = String.Format("{0,-20}", strFengTiaoNo);
                        string strPieceNum = String.Format("{0,-20}", nPieceNum.ToString());
                        string strMaoZhong = String.Format("{0,-20}", nMaoZhong.ToString());
                        string strCBM = String.Format("{0,-20}", dCBM.ToString());



                        strFinal += strGuiNo + strGuiXingSingle + strFengTiaoNo + strPieceNum + strMaoZhong + strCBM + "\n";
                    }

                    coderBlogForm.SetField("Summary2", strFinal);
                    coderBlogForm.SetField("Summary", "SAY TOTAL " + m_Num2Eng[ds2.Tables[0].Rows.Count] + " CONTAINER(S) (" + ds2.Tables[0].Rows.Count + "X" + strGuiXing + ") ONLY");

                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".00 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal + " CBM");

                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("PieceNum", nTotalPieceNum.ToString() + "CARTONS");
                    //coderBlogForm.SetField("GuiCount", ds2.Tables[0].Rows.Count.ToString());
                    //coderBlogForm.SetField("GuiXing1", "x" + strGuiXing);


                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region CMA
        private void ProduceCma(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());

                    //coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    //coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort", ds.Tables[0].Rows[0]["报关港"].ToString());
                    //coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strDay + " " + strMonth + " " + strYear);
                 

                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPort1", strZYPort);
                    coderBlogForm.SetField("ZYPort2", strZYPort);

                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    int nTotalGuiXingWeight = 0;


                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        nTotalGuiXingWeight += m_GuiXing2Weight[strGuiXing];
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strGuiNo = String.Format("{0,-40}", strGuiNo);
                        string strGuiXingSingle = String.Format("{0,-20}", "1 x "+ strGuiXing);

                        string strPieceNum = String.Format("{0,-80}", nPieceNum.ToString() + " CARTONS");
                        string strTare = String.Format("{0,-15}", m_GuiXing2Weight[strGuiXing].ToString());
                        string strMaoZhong = String.Format("{0,-20}", nMaoZhong.ToString() + ".000");
                        string strCBM = String.Format("{0,-15}", dCBM.ToString());

                        strFengTiaoNo = String.Format("{0,-40}", "SEAL " + strFengTiaoNo);


                        strFinal += strGuiNo + strGuiXingSingle + strPieceNum + strMaoZhong + strTare + strCBM + "\n" + strFengTiaoNo + "\n\n";
                    }

                    coderBlogForm.SetField("Summary2", strFinal + "\n\n\n\n\n");
                    coderBlogForm.SetField("Summary", ds2.Tables[0].Rows.Count + "X" + strGuiXing + "\n" + nTotalPieceNum.ToString() + " CARTONS\nSAY TOTAL " 
                        + m_Num2Eng[ds2.Tables[0].Rows.Count] + " CONTAINER(S) (" + ds2.Tables[0].Rows.Count + "X" + strGuiXing + ") ONLY");

                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong.ToString() + ".000");
                    coderBlogForm.SetField("CBM", dCBMTotal.ToString());
                    string strGuiWeight = nTotalGuiXingWeight.ToString();
                    coderBlogForm.SetField("Tare", strGuiWeight.ToString());
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString() + "\nFREIGHT PREPAID");
                    coderBlogForm.SetField("PieceNum", nTotalPieceNum.ToString() + "CARTONS");
                    //coderBlogForm.SetField("GuiCount", ds2.Tables[0].Rows.Count.ToString());
                    //coderBlogForm.SetField("GuiXing1", "x" + strGuiXing);
                    string strGuiCount = "Weight in Kgs Total: " + ds2.Tables[0].Rows.Count.ToString() + " CONTAINER(S)";
                    coderBlogForm.SetField("GuiCount", strGuiCount);

                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region OOCL
        private void ProduceOocl(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    // coderBlogForm.SetField("MDPortMDCountry3", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort1", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());
                    //coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = dtShipDate.Month.ToString().PadLeft(2, '0');
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    //coderBlogForm.SetField("ShipDate1", strMonth + "," + strDay + "," + strYear);
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ShipDate1", strMonth + "/" + strDay + "/" + strYear);
                    coderBlogForm.SetField("ShipDate2", strMonth + "/" + strDay + "/" + strYear);
                    coderBlogForm.SetField("ZYPort", strZYPort);


                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strFinal += strGuiNo.TrimEnd() + " / " + strFengTiaoNo.TrimEnd() + " / " + SplitGuiXing(strGuiXing)
                            + " / " + nPieceNum.ToString() + " CTN(S)" + " / " + nMaoZhong.ToString() + ".00 KG(S)" + " / " + dCBM.ToString() + " CBM / CY-CY" + "\n";
                    }
                    coderBlogForm.SetField("Line", "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");

                    coderBlogForm.SetField("Summary", "GRAND TOTAL:");
                    coderBlogForm.SetField("Summary2", strFinal + "\n\n\n\n");
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".000");
                    coderBlogForm.SetField("CBM", dCBMTotal.ToString());
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("PieceNum", nTotalPieceNum.ToString() + " CTN(S)");
                    coderBlogForm.SetField("GuiCountGuiXing1", "SAY " + m_Num2Eng[ds2.Tables[0].Rows.Count] + " (" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")CONTAINER ONLY");
                    //coderBlogForm.SetField("GuiCountGuiXing2", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    //coderBlogForm.SetField("GuiCountGuiXing2", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")");


                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region UAC
        private void ProduceUac(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DingCangNo2", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    //coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    // coderBlogForm.SetField("MDPortMDCountry3", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort1", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());
                    //coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    //coderBlogForm.SetField("ShipDate1", strMonth + "," + strDay + "," + strYear);
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ShipDate1", strDay + "-" + strMonth + "-" + strYear);
                    coderBlogForm.SetField("ShipDate2", strDay + "-" + strMonth + "-" + strYear);
                    coderBlogForm.SetField("ZYPort", strZYPort);


                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strFinal += strGuiNo.TrimEnd() + " / " + strGuiXing.Substring(0, 2) + " / " + strGuiXing.Substring(2, 2) + " / "
                            + strFengTiaoNo.TrimEnd() + " / " + nPieceNum.ToString() + " PACKAGE(S)" + " / "
                            + " TW:" + nMaoZhong.ToString() + ".000 KGS" + "\n" + "ABOVE CNTR. WEIGHT & CBM :" 
                            + nMaoZhong.ToString() + ".000 KGS " + dCBM.ToString() + " CBM" + "\n";
                    }
                    
                    coderBlogForm.SetField("Summary2", strFinal + "\n\n\n\n");
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong + ".00 KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal.ToString() + " CBM");
                    coderBlogForm.SetField("GoodName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    coderBlogForm.SetField("PieceNum", "TOTAL PACKAGES :" + nTotalPieceNum.ToString());
                    coderBlogForm.SetField("PieceNum2", nTotalPieceNum.ToString() + "CARTON(S)");

                    coderBlogForm.SetField("GuiCountGuiXing", ds2.Tables[0].Rows.Count + " X " + strGuiXing + " STC");
                    //coderBlogForm.SetField("GuiCountGuiXing2", ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing));
                    //coderBlogForm.SetField("GuiCountGuiXing2", m_Num2Eng[ds2.Tables[0].Rows.Count] + "(" + ds2.Tables[0].Rows.Count + "X" + SplitGuiXing(strGuiXing) + ")");


                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region  南美
        private void ProduceNanMei(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    coderBlogForm.SetField("DingCangNo2", ds2.Tables[0].Rows[0]["订仓号"].ToString());
                    //coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort1", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strMonth + "." + strDay + "," + strYear);
                    coderBlogForm.SetField("ShipDate2", strMonth + " " + strDay + " " + strYear);

                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPort", strZYPort);
                    //coderBlogForm.SetField("ZYPort2", strZYPort);

                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    int nTotalGuiXingWeight = 0;


                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        nTotalGuiXingWeight += m_GuiXing2Weight[strGuiXing];
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strFinal += strGuiNo + "\nSN:" + strFengTiaoNo + "\nQTY:" + nPieceNum + "\nCY / CY\n"
                            + "FCL/FCL\nTW:" + m_GuiXing2Weight[strGuiXing].ToString()
                            + "\nGW:" + nMaoZhong + ".000 KGS " + "\nM3:" + dCBM + " CBM" + "\n";
                    }

                    coderBlogForm.SetField("Summary2", strFinal + "\n\n\n\n\n");
                    coderBlogForm.SetField("Summary", SplitGuiXing(strGuiXing) + " CONTAINER\nSAID TO CONTAIN\n"
                        + nTotalPieceNum.ToString() + " CARTONS\n"
                        + ds.Tables[0].Rows[0]["货物种类英文"].ToString() + "\n\n\n");

                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong.ToString() + ".000KGS");
                    coderBlogForm.SetField("CBM", dCBMTotal.ToString()+ "CBM");
                 
                    //coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString() + "\nFREIGHT PREPAID");
                    //coderBlogForm.SetField("PieceNum", nTotalPieceNum.ToString() + "CARTONS");
                    //coderBlogForm.SetField("GuiCount", ds2.Tables[0].Rows.Count.ToString());
                    //coderBlogForm.SetField("GuiXing1", "x" + strGuiXing);
                    string strGuiCount = ds2.Tables[0].Rows.Count.ToString();
                    coderBlogForm.SetField("GuiCount", strGuiCount);

                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region SUMITOMO
        private void ProduceSumitomo(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());

                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort1", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    coderBlogForm.SetField("ShipDate1", strDay + "-" + strMonth + "-" + strYear);


                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPort", strZYPort);
                  

                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    int nTotalGuiXingWeight = 0;


                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        nTotalGuiXingWeight += m_GuiXing2Weight[strGuiXing];
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-200, 200);
                        Decimal f = (Decimal)(a * 0.01);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strGuiNo = String.Format("{0,-20}", strGuiNo);
                        strFengTiaoNo = String.Format("{0,-30}", strFengTiaoNo);
                        string strGuiXingSingle = String.Format("{0,-10}", strGuiXing.Substring(0, 2) + "'/" + strGuiXing.Substring(2, 2));
                        string strFCL = String.Format("{0,-40}", "FCL/FCL");
                        string strPieceNum = String.Format("{0,-20}", nPieceNum.ToString() + " CARTON");
                        
                        string strMaoZhong = String.Format("{0,-20}", nMaoZhong.ToString() + ".00");
                        string strCBM = String.Format("{0,-20}", dCBM.ToString());




                        strFinal += strGuiNo + strFengTiaoNo + strGuiXingSingle + strFCL + strPieceNum + strMaoZhong + strCBM + "\n";
                    }

                    coderBlogForm.SetField("Summary2", strFinal + "\n\n\n\n\n");
       

                    //coderBlogForm.SetField("MaoZhong", nTotalMaoZhong.ToString() + ".000");
                    //coderBlogForm.SetField("CBM", dCBMTotal.ToString());
                    //string strGuiWeight = nTotalGuiXingWeight.ToString();
                    //coderBlogForm.SetField("Tare", strGuiWeight.ToString());
                    //coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString() + "\nFREIGHT PREPAID");
                    coderBlogForm.SetField("Summary", "TOTAL: " + nTotalPieceNum.ToString() + " CARTONS \n" 
                        + ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    //coderBlogForm.SetField("GuiCount", ds2.Tables[0].Rows.Count.ToString());
                    //coderBlogForm.SetField("GuiXing1", "x" + strGuiXing);
                    string strGuiCount = "TOTAL " + ds2.Tables[0].Rows.Count.ToString() + "X" + SplitGuiXing(strGuiXing).Substring(0,3) + " CONTAINER ONLY.";
                    coderBlogForm.SetField("GuiCountGuiXing1", strGuiCount);

                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region TSL
        private void ProduceTsl(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());

                    coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort1", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = m_Month2Eng[dtShipDate.Month].ToUpper();
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ZYPortShipDate", strDay + "-" + strMonth + "-" + strYear + "\n" + strZYPort);


                    
                    //coderBlogForm.SetField("ZYPort1", strZYPort);
                    //coderBlogForm.SetField("ZYPort2", strZYPort);

                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    int nTotalGuiXingWeight = 0;


                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        nTotalGuiXingWeight += m_GuiXing2Weight[strGuiXing];
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strGuiNo = String.Format("{0,-35}", strGuiNo);
                        strFengTiaoNo = String.Format("{0,-30}", "/" + strFengTiaoNo);
                        string strGuiXingSingle = String.Format("{0,-50}", "1 X "
                            + SplitGuiXing(strGuiXing).Substring(0, 3) + " DRY STC " + nPieceNum.ToString() + " CTNS");

                        
                        string strMaoZhong = String.Format("{0,-30}", nMaoZhong.ToString() + ".00");
                        string strCBM = String.Format("{0,-25}", dCBM.ToString());




                        strFinal += strGuiNo + strFengTiaoNo + strGuiXingSingle + strMaoZhong + strCBM + "\n";
                    }

                    coderBlogForm.SetField("Summary2", strFinal + "\n\n\n\n\n");
                 
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong.ToString() + ".00");
                    coderBlogForm.SetField("CBM", dCBMTotal.ToString());
               
                    coderBlogForm.SetField("GoodsName", ds.Tables[0].Rows[0]["货物种类英文"].ToString());
                    //coderBlogForm.SetField("PieceNum", nTotalPieceNum.ToString() + " CNTR(S) ONLY");
                    //coderBlogForm.SetField("GuiCount", ds2.Tables[0].Rows.Count.ToString());
                    //coderBlogForm.SetField("GuiXing1", "x" + strGuiXing);
                    string strGuiCount = ds2.Tables[0].Rows.Count.ToString() + "  CNTR(S) ONLY";
                    coderBlogForm.SetField("GuiCount", strGuiCount);

                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region GLOBEES
        private void ProduceGlobeES(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());

                    //coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    //coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    //coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort1", ds.Tables[0].Rows[0]["报关港"].ToString());
                    coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());
                    string[] strArray = strChuanNameHangCi.Split(' ');
                    string strChuanName = "";
                    for (int k = 0; k < strArray.Length - 1; k++)
                        strChuanName += strArray[k];
                    string strHangCi = strArray[strArray.Length - 1];
                    coderBlogForm.SetField("ShipName", strChuanName);
                    coderBlogForm.SetField("HangCi", strHangCi);



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = dtShipDate.Month.ToString().PadLeft(2, '0');
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ShipDate1", strYear + "/" + strMonth + "/" + strDay);
                    coderBlogForm.SetField("ShipDate2", strYear + "/" + strMonth + "/" + strDay);
                    coderBlogForm.SetField("ZYPort", strZYPort);

                    //coderBlogForm.SetField("ZYPort1", strZYPort);
                    //coderBlogForm.SetField("ZYPort2", strZYPort);

                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    int nTotalGuiXingWeight = 0;


                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        nTotalGuiXingWeight += m_GuiXing2Weight[strGuiXing];
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strGuiNo = String.Format("{0,-20}", strGuiNo);
                        string strGuiXingSingle = String.Format("{0,-25}", "/ " + strGuiXing.Substring(0,2)
                            + " " + strGuiXing.Substring(2,2));
                           

                        strFengTiaoNo = String.Format("{0,-25}", strFengTiaoNo);

                        string strPieceNum = String.Format("{0,-20}", nPieceNum.ToString() + " CARTONS");
                        string strMaoZhong = String.Format("{0,-20}", nMaoZhong.ToString() + ".00KG");
                        string strCBM = String.Format("{0,-15}", dCBM.ToString() + ".CBMS");




                        strFinal += strGuiNo + strGuiXingSingle + strFengTiaoNo + strPieceNum + strMaoZhong + strCBM + "\n";
                    }

                    coderBlogForm.SetField("Summary2", strFinal + "\n\n\n\n\n");
                    string strTotalMaoZhong = String.Format("{0,-20}", nTotalMaoZhong.ToString() + ".00KG");
                    string strTotalCBM = String.Format("{0,-20}", dCBMTotal.ToString() + ".CBMS");
                    string strTotalPieceNum = String.Format("{0,-40}", "Total:   (**"
                        + nTotalPieceNum.ToString() + "**) CARTONS ONLY");
                    coderBlogForm.SetField("Summary", strTotalPieceNum + strTotalMaoZhong + strTotalCBM);
                    coderBlogForm.SetField("MaoZhong", nTotalMaoZhong.ToString() + ".00");
                    coderBlogForm.SetField("CBM", dCBMTotal.ToString());

                    coderBlogForm.SetField("GoodsNameEtc", ds.Tables[0].Rows[0]["货物种类英文"].ToString() + "\n\n"
                        + "SHIPPER'S LOAD, COUNT&\nSEALED");
                    
                    //coderBlogForm.SetField("GuiCount", ds2.Tables[0].Rows.Count.ToString());
                    //coderBlogForm.SetField("GuiXing1", "x" + strGuiXing);
                    coderBlogForm.SetField("PieceNum", nTotalPieceNum.ToString() + " CARTONS");
                    string strGuiCount = ds2.Tables[0].Rows.Count.ToString();
                    coderBlogForm.SetField("GuiCount", strGuiCount);

                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        #region MSC
        private void ProduceMsc(string strTidanTemplete)
        {
            try
            {
                DataSet ds = m_bllTiDanTab.GetAllRecord("TiDanTabid = '" + m_nSelectTiDanTabID + "'");
                DataSet ds2 = m_bllTiDanDetailTab.GetDetailInfo("TiDanTabID = '" + m_nSelectTiDanTabID + "'");
                if (ds.Tables[0].Rows.Count > 0 && ds2.Tables[0].Rows.Count > 0)
                {
                    string templateFile = Path.Combine(Application.StartupPath + m_strTidanTempletFilePath, strTidanTemplete + ".pdf");
                    if (!Directory.Exists(m_strFolder))//判断是否存在
                    {
                        Directory.CreateDirectory(m_strFolder);//创建新路径
                    }
                    string tempPDF = Path.Combine(m_strFolder, ds.Tables[0].Rows[0]["合同编号"].ToString() + ".pdf");

                    PdfReader reader = new PdfReader(templateFile);
                    FileStream fFileStream = new FileStream(tempPDF, FileMode.Create);
                    //iTextSharp.text.Font font = new iTextSharp.text.Font(BaseFont.createFont(@"C:\\WINDOWS\\Fonts\\SIMFANG.TTF", "Identity-H", BaseFont.NOT_EMBEDDED), 12f);
                    //进行PDF字段操作
                    PdfStamper stamper = new PdfStamper(reader, fFileStream);
                    AcroFields coderBlogForm = stamper.AcroFields;
                    //foreach (string str in coderBlogForm.Fields.Keys)
                    //{
                    //    Console.WriteLine(str);
                    //}
                    //填充PDF里的字段内容
                    coderBlogForm.SetField("Shipper", ds.Tables[0].Rows[0]["提单Shipper"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("Consignee", ds.Tables[0].Rows[0]["提单Consignee"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("DingCangNo1", ds2.Tables[0].Rows[0]["订仓号"].ToString());

                    //coderBlogForm.SetField("DeliveryAgent", ds.Tables[0].Rows[0]["目的港货代"].ToString() + "\n\n\n\n");
                    coderBlogForm.SetField("NotifyPart", ds.Tables[0].Rows[0]["NotifyPart"].ToString());
                    coderBlogForm.SetField("MDPortMDCountry1", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());
                    //coderBlogForm.SetField("MDPortMDCountry2", ds.Tables[0].Rows[0]["目的国港口"].ToString() + "," + ds.Tables[0].Rows[0]["目的国家"].ToString());

                    string strChuanNameHangCi = ds.Tables[0].Rows[0]["船名航次"].ToString();
                    coderBlogForm.SetField("ShipNameHangCi", strChuanNameHangCi);
                    coderBlogForm.SetField("BGPort", ds.Tables[0].Rows[0]["报关港"].ToString());
                    //coderBlogForm.SetField("BGPort2", ds.Tables[0].Rows[0]["报关港"].ToString());
                    



                    DateTime dtShipDate = (DateTime)ds.Tables[0].Rows[0]["ShipDate"];
                    string strMonth = dtShipDate.Month.ToString().PadLeft(2, '0');
                    string strYear = dtShipDate.Year.ToString();
                    string strDay = dtShipDate.Day.ToString().PadLeft(2, '0');
                    string strZYPort = ds.Tables[0].Rows[0]["装运港"].ToString();
                    coderBlogForm.SetField("ShipDate1", strYear + "-" + strMonth + "-" + strDay);
                    coderBlogForm.SetField("ZYPortShipDate", strZYPort + "\n" + strYear + "-" + strMonth + "-" + strDay);
                   

                    //coderBlogForm.SetField("ZYPort1", strZYPort);
                    //coderBlogForm.SetField("ZYPort2", strZYPort);

                    int nTotalMaoZhong = 0;
                    int nTotalPieceNum = 0;
                    Decimal dCBMTotal = 0;
                    string strFinal = "";
                    string strGuiXing = "";
                    int nTotalGuiXingWeight = 0;


                    for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
                    {
                        string strGuiNo = ds2.Tables[0].Rows[i]["柜号"].ToString();
                        string strFengTiaoNo = ds2.Tables[0].Rows[i]["封条号"].ToString();
                        string strGuiXingName = ds2.Tables[0].Rows[i]["柜型"].ToString();
                        strGuiXing = strGuiXingName;
                        string strGuiXingTypeName = ds2.Tables[0].Rows[i]["柜型型号"].ToString();
                        int nMaoZhong = (int)ds2.Tables[0].Rows[i]["毛重"];
                        int nPieceNum = (int)ds2.Tables[0].Rows[i]["件数"];

                        nTotalMaoZhong += nMaoZhong;
                        nTotalPieceNum += nPieceNum;
                        nTotalGuiXingWeight += m_GuiXing2Weight[strGuiXing];
                        System.Threading.Thread.Sleep(200);
                        Random rd = new Random();

                        int a = rd.Next(-2000, 2000);
                        Decimal f = (Decimal)(a * 0.001);
                        Decimal dCBM = m_GuiXing2CBM[strGuiXingName] + f;
                        dCBMTotal += dCBM;

                        strGuiNo = String.Format("{0,-50}", strGuiNo);
                        string strPieceNum = String.Format("{0,-150}", nPieceNum.ToString() + " Carton(s) of");
                        string strMaoZhong = String.Format("{0,-15}", nMaoZhong.ToString() + ".0000kgs.");
                        string strCBM = String.Format("{0,-15}", dCBM.ToString() + "cu. m.");
                        
                        string strGuiXingSingle = strGuiXing.Substring(0, 2) 
                            + strGuiXing.Substring(2, 2) == "GP" ? "'General Purpose" : "'High Cube";

                        string strEmpty = String.Format("{0,-63}", "");
                        string strGoodsName = ds.Tables[0].Rows[0]["货物种类英文"].ToString();

                        string strFenTiaoLabel = "Seal Number:";
                        strFengTiaoNo = String.Format("{0,-55}", strFengTiaoNo);

                        string strFCL = "FCL/FCL";


                        strFinal += strGuiNo + strPieceNum + strMaoZhong + strCBM + "\n"
                            + strGuiXingSingle + "\n"
                            + strEmpty + strGoodsName + "\n"
                            + strFenTiaoLabel + "\n"
                            + strFengTiaoNo + strFCL + "\n"
                            + "Tare Weight:" + m_GuiXing2Weight[strGuiXing].ToString() + "kgs.\n"
                            + "Marks and Numbers:" + "\n"
                            + "N/M\n\n";
                    }
                    coderBlogForm.SetField("Summary", "TTL:" + m_Num2Eng[ds2.Tables[0].Rows.Count]
                        + " CONTAINERS ONLY\nFREIGHT PREPAID");
                    coderBlogForm.SetField("Summary2", strFinal + "\n\n\n\n\n");
                    string strTotalMaoZhong = nTotalMaoZhong.ToString() + ".000kgs.";
                    string strTotalCBM = dCBMTotal.ToString() + "cu. m.";
   
                    coderBlogForm.SetField("MaoZhong", strTotalMaoZhong);
                    coderBlogForm.SetField("CBM", strTotalCBM);

                    //coderBlogForm.SetField("GoodsNameEtc", ds.Tables[0].Rows[0]["货物种类英文"].ToString() + "\n\n"
                    //    + "SHIPPER'S LOAD, COUNT&\nSEALED");

                    //coderBlogForm.SetField("GuiCount", ds2.Tables[0].Rows.Count.ToString());
                    //coderBlogForm.SetField("GuiXing1", "x" + strGuiXing);
                    //coderBlogForm.SetField("PieceNum", nTotalPieceNum.ToString() + " CARTONS");
                    string strGuiCount = ds2.Tables[0].Rows.Count.ToString();
                    coderBlogForm.SetField("GuiCount", strGuiCount + "     cntrs");

                    stamper.Close();
                    fFileStream.Close();
                    reader.Close();
                    MessageBox.Show(ds.Tables[0].Rows[0]["合同编号"].ToString() + "提单导出成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }
                else
                {
                    MessageBox.Show("提单信息不全!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

        }
        #endregion
        private void buttonExport_Click(object sender, EventArgs e)
        {
            switch (this.comboBoxTiDanTemplete.Text.ToUpper())
            {
                case "MAERSK":
                    {
                        ProduceMaersk(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "SAFMARINE":
                    {
                        ProduceSafmarine(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "CITITRANS":
                    {
                        ProduceCititrans(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "INTERGLOBO":
                    {
                        ProduceInterglobo(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "PANTAINER":
                    {
                        ProducePantainer(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "XINLUO":
                    {
                        ProduceXinluo(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "JUST":
                    {
                        ProduceJust(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "SUMMIT":
                    {
                        ProduceSummit(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "IFL":
                    {
                        ProduceIfl(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "ANL":
                    {
                        ProduceAnl(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "GSL":
                    {
                        ProduceGsl(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "SEAMASTER":
                    {
                        ProduceSeaMaster(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "CMA":
                    {
                        ProduceCma(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "OOCL":
                    {
                        ProduceOocl(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "UAC":
                    {
                        ProduceUac(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "南美":
                    {
                        ProduceNanMei(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "SUMITOMO":
                    {
                        ProduceSumitomo(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "TSL":
                    {
                        ProduceTsl(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "GLOBEES":
                    {
                        ProduceGlobeES(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                case "MSC":
                    {
                        ProduceMsc(this.comboBoxTiDanTemplete.Text.ToUpper());
                        break;
                    }
                default:
                    break;
            }
        }

        private void comboBoxTargetCountry_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                string strContractNo = this.comboBoxTargetCountry.SelectedValue.ToString();
                int nID = Convert.ToInt32(strContractNo, 10);
                DataSet ds = m_bllMDCountryTab.GetMDCountryTiDanInfo("MDCountryTab.MDCountryTabID = '" + nID + "'");
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    string strTiDanConsigneeName = ds.Tables[0].Rows[0]["TiDanConsigneeName"].ToString();
                    string strTiDanMDCountryPortName = ds.Tables[0].Rows[0]["TiDanMDCountryPortName"].ToString();
                    string strTiDanDeliveryAgentName = ds.Tables[0].Rows[0]["TiDanDeliveryAgentName"].ToString();
                    this.richTextBoxConsignee.Text = strTiDanConsigneeName;
                    this.richTextBoxMDPort.Text = strTiDanMDCountryPortName;
                    this.richTextBoxDeliveryAgent.Text = strTiDanDeliveryAgentName;
                }
                else
                {
                    this.richTextBoxConsignee.Text = "";
                    this.richTextBoxMDPort.Text = "";
                    this.richTextBoxDeliveryAgent.Text = "";
                }
      

            }
            catch { }
            
        }
        public static void ultraGrid1_InitializeRowFilter(Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            //ultraGrid1.DisplayLayout.Override.RowSizing = RowSizing.AutoFree;
            //foreach (UltraGridColumn ugc in ultraGrid1.DisplayLayout.Bands[0].Columns)
            //    ugc.PerformAutoResize();
            // FILTER ROW FUNCTIONALITY RELATED ULTRAGRID SETTINGS
            //e.Layout.Override.RowFilterAction = RowFilterAction.DisableFilteredOutRows;
            // ----------------------------------------------------------------------------------
            // Enable the the filter row user interface by setting the FilterUIType to FilterRow.
            e.Layout.Override.FilterUIType = FilterUIType.FilterRow;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // FilterEvaluationTrigger specifies when UltraGrid applies the filter criteria typed 
            // into a filter row. Default is OnCellValueChange which will cause the UltraGrid to
            // re-filter the data as soon as the user modifies the value of a filter cell.
            e.Layout.Override.FilterEvaluationTrigger = FilterEvaluationTrigger.OnCellValueChange;
            //e.Layout.Override.RowFilterMode = RowFilterMode.AllRowsInBand;
            // By default the UltraGrid selects the type of the filter operand editor based on
            // the column's DataType. For DateTime and boolean columns it uses the column's editors.
            // For other column types it uses the Combo. You can explicitly specify the operand
            // editor style by setting the FilterOperandStyle on the override or the individual
            // columns.

            e.Layout.Override.FilterOperandStyle = FilterOperandStyle.DropDownList;

            // By default UltraGrid displays user interface for selecting the filter operator. 
            // You can set the FilterOperatorLocation to hide this user interface. This
            // property is available on column as well so it can be controlled on a per column
            // basis. Default is WithOperand. This property is exposed off the column as well.
            e.Layout.Override.FilterOperatorLocation = FilterOperatorLocation.WithOperand;

            // By default the UltraGrid uses StartsWith as the filter operator. You use
            // the FilterOperatorDefaultValue property to specify a different filter operator
            // to use. This is the default or the initial filter operator value of the cells
            // in filter row. If filter operator user interface is enabled (FilterOperatorLocation
            // is not set to None) then that ui will be initialized to the value of this
            // property. The user can then change the operator as he/she chooses via the operator
            // drop down.
            e.Layout.Override.FilterOperatorDefaultValue = FilterOperatorDefaultValue.StartsWith;

            // FilterOperatorDropDownItems property can be used to control the options provided
            // to the user for selecting the filter operator. By default UltraGrid bases 
            // what operator options to provide on the column's data type. This property is
            // avaibale on the column as well.
            //e.Layout.Override.FilterOperatorDropDownItems = FilterOperatorDropDownItems.All;

            // By default UltraGrid displays a clear button in each cell of the filter row
            // as well as in the row selector of the filter row. When the user clicks this
            // button the associated filter criteria is cleared. You can use the 
            // FilterClearButtonLocation property to control if and where the filter clear
            // buttons are displayed.
            e.Layout.Override.FilterClearButtonLocation = FilterClearButtonLocation.RowAndCell;

            // Appearance of the filter row can be controlled using the FilterRowAppearance proeprty.
            e.Layout.Override.FilterRowAppearance.BackColor = Color.LightYellow;

            // You can use the FilterRowPrompt to display a prompt in the filter row. By default
            // UltraGrid does not display any prompt in the filter row.
            e.Layout.Override.FilterRowPrompt = "Click here to filter data...";

            // You can use the FilterRowPromptAppearance to change the appearance of the prompt.
            // By default the prompt is transparent and uses the same fore color as the filter row.
            // You can make it non-transparent by setting the appearance' BackColorAlpha property 
            // or by setting the BackColor to a desired value.
            e.Layout.Override.FilterRowPromptAppearance.BackColorAlpha = Alpha.Opaque;

            // By default the prompt is spread across multiple cells if it's bigger than the
            // first cell. You can confine the prompt to a particular cell by setting the
            // SpecialRowPromptField property off the band to the key of a column.
            //e.Layout.Bands[0].SpecialRowPromptField = e.Layout.Bands[0].Columns[0].Key;

            // Display a separator between the filter row other rows. SpecialRowSeparator property 
            // can be used to display separators between various 'special' rows, including for the
            // filter row. This property is a flagged enum property so it can take multiple values.
            e.Layout.Override.SpecialRowSeparator = SpecialRowSeparator.FilterRow;

            // You can control the appearance of the separator using the SpecialRowSeparatorAppearance
            // property.
            e.Layout.Override.SpecialRowSeparatorAppearance.BackColor = Color.FromArgb(233, 242, 199);

            //   UltraGridBand band = e.Layout.Bands[0];
            //   band.ColumnFilters["原币金额"].FilterConditions.Clear();
            //   band.ColumnFilters["原币金额"].FilterConditions.Add(

            //FilterComparisionOperator.GreaterThan, 5);
            //   band.ColumnFilters["原币金额"].FilterConditions.Add(

            //FilterComparisionOperator.LessThan, 10);
            //   band.ColumnFilters["原币金额"].LogicalOperator = FilterLogicalOperator.And;
        }
        private void ultraGrid1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
        {
            if (this.checkBox1.Checked == true)
                ultraGrid1_InitializeRowFilter(e);
            else
                ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            ClassUltraGridCommonSet.InitUltraWinGridRowNumSetting(e);
        }
        private void ShowAllMXRecordInDataGridView(int nSelectTiDanTabID)
        {
            ultraGrid2.DataSource = null;
            DataSet ds = m_bllTiDanDetailTab.GetDetailInfo("TiDanDetailTab.TiDanTabID = '" + nSelectTiDanTabID + "'");
            if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ultraGrid2.DataSource = ds.Tables[0];
                ultraGrid2.DisplayLayout.Bands[0].Columns[0].Hidden = true;
                ultraGrid2.DisplayLayout.Bands[0].Columns[1].Hidden = true;
            }
           
        }
        private void cellTiDanTabClick()
        {
            this.ultraGrid1.Dock = DockStyle.None;
            this.groupBoxGoodsDetail.Visible = true;
            DGBY.Model.TiDanTab modelTiDanTab = m_bllTiDanTab.GetModel(m_nSelectTiDanTabID);
            if (modelTiDanTab != null)
            {
                this.textBoxNotifyPart.Text = modelTiDanTab.NotifyPart;
                this.textBoxShipNameHangCi.Text = modelTiDanTab.ShipNameHangCi;
                this.dateTimePickerMakeProtocolDate.Value = modelTiDanTab.ShipDate;

                this.richTextBoxShipper.Text = modelTiDanTab.TiDanShipper;
                this.richTextBoxConsignee.Text = modelTiDanTab.TiDanConsignee;
                this.richTextBoxDeliveryAgent.Text = modelTiDanTab.TiDanDeliveryAgent;
                this.richTextBoxMDPort.Text = modelTiDanTab.TiDanMDCountryPort;

                if (modelTiDanTab.PaidanRegisterTabID != null)
                    this.comboBoxContractNo.SelectedValue = modelTiDanTab.PaidanRegisterTabID;
                if (modelTiDanTab.TiDanTempleteTabID != null)
                    this.comboBoxTiDanTemplete.SelectedValue = modelTiDanTab.TiDanTempleteTabID;
                //if (modelTiDanTab.TiDanShipperTabID != null)
                //    this.comboBoxShipper.SelectedValue = modelTiDanTab.TiDanShipperTabID;
                //if (modelTiDanTab.TiDanConsigneeTabID != null)
                //    this.comboBoxConsignee.SelectedValue = modelTiDanTab.TiDanConsigneeTabID;
                //if (modelTiDanTab.TiDanMDCountryPortTabID != null)
                //    this.comboBoxTiDanMDCountryPort.SelectedValue = modelTiDanTab.TiDanMDCountryPortTabID;
                //if (modelTiDanTab.TiDanDeliveryAgentTabID != null)
                //    this.comboBoxDeliveryAgentTab.SelectedValue = modelTiDanTab.TiDanDeliveryAgentTabID;
                if (modelTiDanTab.FactoryGoodsCHN2ENGTabID != null)
                    this.comboBoxGoodsEng.SelectedValue = modelTiDanTab.FactoryGoodsCHN2ENGTabID;
                if (modelTiDanTab.MDCountryTabID != null)
                    this.comboBoxTargetCountry.SelectedValue = modelTiDanTab.MDCountryTabID;
                if (modelTiDanTab.BGHarborTabID != null)
                    this.comboBoxBGPort.SelectedValue = modelTiDanTab.BGHarborTabID;
                if (modelTiDanTab.ZYHarborTabID != null)
                    this.comboBoxPort.SelectedValue = modelTiDanTab.ZYHarborTabID;

                ShowAllMXRecordInDataGridView(m_nSelectTiDanTabID);
                //this.textBoxDJNo.Text = modelTiDanTab.BGPackDJNo.ToString();
                //ShowAllMXRecordInDataGridView(m_nSelectBGPackingTabID);
            }
            else
            {

            }
        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;


            string strBGPackingTabID = this.ultraGrid1.Rows[this.ultraGrid1.ActiveCell.Row.Index].Cells[0].Text;
            m_nSelectTiDanTabID = Convert.ToInt32(strBGPackingTabID, 10);
            cellTiDanTabClick();
        }
        private void SetPanelLocation()
        {

            //this.panel1.Location = new Point(2, 170);
            //this.panel1.Size = new Size(this.panel2.Location.X, this.panel2.Location.Y + ClientRectangle.Height * 47 / 100);
        }
        private void Frm_TiDanMng_Resize(object sender, EventArgs e)
        {
            //SetPanelLocation();
        }

        private void buttonSaveShipper_Click(object sender, EventArgs e)
        {
            try
            {
                DGBY.Model.TiDanShipperTab modelTiDanShipperTab = new DGBY.Model.TiDanShipperTab();
                modelTiDanShipperTab.TiDanShipperName = this.richTextBoxShipper.Text;
                modelTiDanShipperTab.ReservField1 = "";

                m_bllTiDanShipperTab.Add(modelTiDanShipperTab);
                Frm_Main.Log2DB(this.Text, "保存Shipper", modelTiDanShipperTab.TiDanShipperName);
                MessageBox.Show("数据添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
               

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void buttonConsigneeSave_Click(object sender, EventArgs e)
        {
            try
            {
                DGBY.Model.TiDanConsigneeTab modelTiDanConsigneeTab = new DGBY.Model.TiDanConsigneeTab();
                modelTiDanConsigneeTab.TiDanConsigneeName = this.richTextBoxConsignee.Text;
                modelTiDanConsigneeTab.ReservField1 = "";

                if (this.comboBoxTargetCountry.SelectedValue != null)
                    modelTiDanConsigneeTab.MDCountryTabID = Convert.ToInt32(this.comboBoxTargetCountry.SelectedValue.ToString(), 10);

                m_bllTiDanConsigneeTab.Add(modelTiDanConsigneeTab);

                Frm_Main.Log2DB(this.Text, "保存目的港货代", modelTiDanConsigneeTab.TiDanConsigneeName);
                MessageBox.Show("数据添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void buttonDeliveryAgentSave_Click(object sender, EventArgs e)
        {
            try
            {
                DGBY.Model.TiDanDeliveryAgentTab modelTiDanDeliveryAgentTab = new DGBY.Model.TiDanDeliveryAgentTab();
                modelTiDanDeliveryAgentTab.TiDanDeliveryAgentName = this.richTextBoxDeliveryAgent.Text;
                modelTiDanDeliveryAgentTab.ReservField1 = "";

                if (this.comboBoxTargetCountry.SelectedValue != null)
                    modelTiDanDeliveryAgentTab.MDCountryTabID = Convert.ToInt32(this.comboBoxTargetCountry.SelectedValue.ToString(), 10);

                m_bllTiDanDeliveryAgentTab.Add(modelTiDanDeliveryAgentTab);


                Frm_Main.Log2DB(this.Text, "保存目的港货代", modelTiDanDeliveryAgentTab.TiDanDeliveryAgentName);
                MessageBox.Show("数据添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void buttonMDPortSave_Click(object sender, EventArgs e)
        {
            try
            {
                DGBY.Model.TiDanMDCountryPortTab modelTiDanMDCountryPortTab = new DGBY.Model.TiDanMDCountryPortTab();
                modelTiDanMDCountryPortTab.TiDanMDCountryPortName = this.richTextBoxMDPort.Text;
                modelTiDanMDCountryPortTab.ReservField1 = "";

                if (this.comboBoxTargetCountry.SelectedValue != null)
                    modelTiDanMDCountryPortTab.MDCountryTabID = Convert.ToInt32(this.comboBoxTargetCountry.SelectedValue.ToString(), 10);

                m_bllTiDanMDCountryPortTab.Add(modelTiDanMDCountryPortTab);

                Frm_Main.Log2DB(this.Text, "保存目的国家港口", modelTiDanMDCountryPortTab.TiDanMDCountryPortName);
                MessageBox.Show("数据添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void buttonConsigneeChoose_Click(object sender, EventArgs e)
        {
            Frm_TiDanConsignee frm_TiDanConsignee = new Frm_TiDanConsignee((int)this.comboBoxTargetCountry.SelectedValue);
            frm_TiDanConsignee.StartPosition = FormStartPosition.CenterScreen;

            if (frm_TiDanConsignee.ShowDialog() == DialogResult.OK)
            {
                this.richTextBoxConsignee.Text = frm_TiDanConsignee.m_strReturn;
            }
        }

        private void buttonShipperChoose_Click(object sender, EventArgs e)
        {
            Frm_TiDanShipper frm_TiDanShipper = new Frm_TiDanShipper();
            frm_TiDanShipper.StartPosition = FormStartPosition.CenterScreen;

            if (frm_TiDanShipper.ShowDialog() == DialogResult.OK)
            {
                this.richTextBoxShipper.Text = frm_TiDanShipper.m_strReturn;
            }
        }

        private void buttonDeliveryAgentChoose_Click(object sender, EventArgs e)
        {
            Frm_TiDanDeliveryAgentTab frm_TiDanDeliveryAgentTab = new Frm_TiDanDeliveryAgentTab((int)this.comboBoxTargetCountry.SelectedValue);
            frm_TiDanDeliveryAgentTab.StartPosition = FormStartPosition.CenterScreen;

            if (frm_TiDanDeliveryAgentTab.ShowDialog() == DialogResult.OK)
            {
                this.richTextBoxDeliveryAgent.Text = frm_TiDanDeliveryAgentTab.m_strReturn;
            }
        }

        private void buttonMDPortChoose_Click(object sender, EventArgs e)
        {
            Frm_TiDanMDCountryPort frm_TiDanMDCountryPort = new Frm_TiDanMDCountryPort((int)this.comboBoxTargetCountry.SelectedValue);
            frm_TiDanMDCountryPort.StartPosition = FormStartPosition.CenterScreen;

            if (frm_TiDanMDCountryPort.ShowDialog() == DialogResult.OK)
            {
                this.richTextBoxMDPort.Text = frm_TiDanMDCountryPort.m_strReturn;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
        }

   
    }
}
